package com.campus.controller;

import com.campus.common.Result;
import com.campus.service.HotRankingService;
import com.campus.service.impl.HotRankingServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestParam;

@RestController
@RequestMapping("/api")
public class HotRankingController {
    @Autowired
    private HotRankingService hotRankingService;

    @GetMapping("/api/hot-ranking")
    public Result hotPosts(@RequestParam(defaultValue = "10") Integer limit, 
                          @RequestParam(defaultValue = "week") String timeRange) {
        Result hotPosts = hotRankingService.getHotPosts(limit, timeRange);
        return hotPosts;
    }

    @GetMapping("/api/hot-ranking/category/{categoryId}")
    public Result categoryHotPosts(@PathVariable String categoryId, 
                                  @RequestParam(defaultValue = "10") Integer limit, 
                                  @RequestParam(defaultValue = "week") String timeRange) {
        Result hotPosts = hotRankingService.getCategoryHotPosts(categoryId, limit, timeRange);
        return hotPosts;
    }

    /**
     * 统计今日发布的帖子发布数量
     */
    @GetMapping("/api/stats/posts/{date}/{categoryId}")
    public Result getTodayPostsCountAndCategory(@PathVariable("date") String date,@PathVariable("categoryId") String categoryId) {
        Result result = hotRankingService.getPostCount(date,categoryId);
        return result;
    }
    @GetMapping("/api/stats/posts/{date}")
    public Result getTodayPostsCount(@PathVariable("date") String date,String categoryId) {
        Result result = hotRankingService.getPostCount(date,categoryId);
        return result;
    }
    /**
     * 统计今日发布的帖子浏览量
     */
    @GetMapping("/api/stats/views/{date}")
    public Result getTodayPostsViewCount(@PathVariable("date") String date) {
        Result result = hotRankingService.getPostViewCount(date);
        return result;
    }
}